package com.fcai.microserv.springmvc.converter;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.convert.converter.Converter;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

@NoArgsConstructor
@AllArgsConstructor
@Getter
public class String2LocalDateConverter implements Converter<String, LocalDate> {

    private String pattern;

    @Override
    public LocalDate convert(String s) {
        if(StringUtils.isEmpty(s)) {
            return null;
        }
        return LocalDate.parse(s,DateTimeFormatter.ofPattern(pattern));
    }
}
